#include <stdio.h>
#include <ctype.h>

/*
 * 程序块里面变量范围限制住了
 */
#define swap(t, x, y) { t _z = x; x = y; y = _z;}

/*
 * 经典程序，atof
 *  有意思的点是对E和小数点的判断，里面细节状态的转换很有意思
 */
double atof(char s[]){

    double  val, rpower = 1.0, power;
    int i, sign,  res, rsign;

    for ( i = 0; isspace(s[i]); ++i)
        ;
    sign = (s[i] == '-') ? -1 : 1;
    if(s[i] == '+' || s[i] == '-')
        i++;

    for ( val = 0.0; isdigit(s[i]) ; ++i)
        val = 10.0 * val + (s[i] - '0');
    if(s[i] == '.')
        i++;
    for ( power = 1.0;  isdigit(s[i])  ; ++i) {
        val = 10.0 * val + (s[i] - '0');
        power *= 10.0;
    }
    if(s[i] == 'e' || s[i] == 'E'){
        i++;

        rsign = (s[i] == '-') ? -1:1;
        if(s[i] == '+' || s[i] == '-')
            i++;

        for ( res = 0;  isdigit(s[i]) ; ++i)
            res = 10 * res + (s[i] - '0');
        if (rsign == 1){
            for ( rpower = 1.0; res > 0 ; res--)
                rpower *= 10;
        } else{
            for ( rpower = 1.0; res > 0 ; res--)
                rpower /= 10;
        }
    }

    return sign * val /power * rpower;
}
int main() {
    printf("%15.14f\n",atof("-123.45e-6"));
    int a = 1, b =2;
    swap(int, a, b);

    printf("a=%d, b=%d",a , b);
    return 0;
}











